import 'package:get/get.dart';
import 'package:ride_rex/main/mine/block_list/block_bean.dart';
import 'package:ride_rex/net/common_global_url.dart';
import 'package:ride_rex/net/common_net.dart';
import 'package:ride_rex/person_detail/person_detail_logic.dart';
import 'package:ylm_ui_kit/ylm_ui_kit.dart';

class ApiMineBlockList extends CommonApi {
  ApiMineBlockList.list() : super(CommonGlobalUrl.blockList);

  ApiMineBlockList.unblock({required String userId})
      : super(CommonGlobalUrl.removeFromBlockList, params: {'blockUserId': userId});
}

class MineBlockListLogic extends GetxController with OnceClick {
  List<BlockListBean> blockList = [];

  @override
  void onReady() async {
    super.onReady();

    Loading.show();
    dynamic json = await ApiMineBlockList.list().post();
    blockList = await CommonJson.getList(json, (json) => BlockListBean.fromJson(json));
    update();
    Loading.dismiss();
  }

  Future unblock(String userId) async {
    if (userId.empty) return;
    startOnce(() async {
      CommonLogic.unblock(userId);
      blockList.removeWhere((element) => element.broadcasterId == userId);
      update();
      Loading.toast('Unblock success', closeLoading: true);
    });
  }
}
